package com.imau.common.entiry;

import lombok.Data;

/**
 * 统一返回结果
 * @author yangzj
 * @date 2024-05-23
 * @version 1.0
 */
@Data
public class ResultEntity {
    /**是否成功*/
    private boolean success;
     /**返回码*/
    private Integer code;
    /**返回信息*/
    private String message;
    /**返回数据*/
    private Object data;

    public ResultEntity(boolean success, Integer code, String message, Object data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResultEntity(boolean success, Integer code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
    }

    public ResultEntity(ResultCode resultCode) {
        this.success = resultCode.getSuccess();
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();

    }

    public ResultEntity(ResultCode code,Object data)
    {
        this.success = code.getSuccess();
        this.code = code.getCode();
        this.message=code.getMessage();
        this.data =data;
    }

    //预定义 常见的返回结果静态方法
    public static ResultEntity SUCCESS(){

        return new ResultEntity(ResultCode.SUCCESS);
    }

    public static ResultEntity ERROR()
    {
        return  new ResultEntity(ResultCode.SERVER_ERROR);
    }

    public static ResultEntity FAIL()
    {
        return  new ResultEntity(ResultCode.FAIL);
    }
}
